package org.jumiz.telnet.play;

import java.util.Random;

/**
 *
 */
public class GuessingNumbers extends AbstractPlay {

    int num = 0;

    int max = 1000;

    int min = 0;

    private boolean end;

    @Override
    public String first(String common) {
        this.num = new Random().nextInt(max);
        return "好的，我想到了一个数字，范围在" + min + "-" + max + "，开始猜吧！\n";
    }

    @Override
    public String next(String common) {
        int guessNum = Integer.parseInt(common);
        if (guessNum > this.num) {
            max = Math.min(max, guessNum);
            return "猜大了，往小了再试试？" + min + "-" + max + "\n";
        }
        if (guessNum < this.num) {
            min = Math.max(min, guessNum);
            return "猜小了，往大了再试试？" + min + "-" + max + "\n";
        }
        end = true;
        return "恭喜您猜对了！\n";
    }

    @Override
    public String end(String common) {
        return "欢迎下次来玩！\n";
    }

    @Override
    public String name() {
        return "猜数字";
    }

    @Override
    public GuessingNumbers clone() {
        return new GuessingNumbers();
    }

    @Override
    public boolean isEnd() {
        return end;
    }
}
